<template>
  <div class="new-yard">
    <!-- 顶部Banner -->
    <div class="banner">
      <img :src="bannerList?.[0]?.bannerUrl || defaultBanner" alt="站院横幅">
    </div>

    <!-- 主要内容区域 -->
    <div class="container">
      <!-- 标题区域 -->
      <h1 class="title">{{ courtyardInfo?.courtyardName || '站院介绍' }}</h1>

      <!-- 基地概况 -->
      <div class="section">
        <h2 class="section-title">基地概况</h2>
        <div class="section-content" v-html="courtyardInfo?.introduce || '暂无介绍内容'"></div>
      </div>


      <!-- 驻站专家团队 -->
      <div class="section experts-section" v-if="experts?.length">
        <h2 class="section-title">驻站专家团队</h2>
        <div class="experts-container">
          <div class="expert-card" v-for="expert in experts" :key="expert.professorId" @click="goToExpertDetail(expert.professorId)">
            <div class="expert-photo">
              <img :src="expert.photo || defaultExpertPhoto" :alt="expert.name">
            </div>
            <div class="expert-info">
              <div class="expert-name">{{ expert.name }}</div>
              <div class="expert-title">{{ expert.title }}</div>
              <div class="expert-major">{{ expert.major }}</div>
              <div class="expert-contact" v-if="expert.contact">{{ expert.contact }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { pageBanner, pageProfessorMien, getCourtyardById } from '@/api/home';

const router = useRouter();

const id = computed(() => router?.currentRoute?.value?.query.yardId);

// 数据定义
const bannerList = ref([]);
const courtyardInfo = ref({});
const experts = ref([]);

// 默认图片
const defaultBanner = 'https://via.placeholder.com/1200x300/068043/ffffff?text=站院横幅';
const defaultExpertPhoto = 'https://via.placeholder.com/200x250/f0f0f0/666666?text=专家照片';

// 获取顶部Banner
const getPageBanners = async () => {
  try {
    const params = {
      params: {
        status: true,
        courtyardId: id.value
      },
      page: {
        pageSize: 1,
        pageNum: 1,
      }
    };
    const ret = await pageBanner(params);
    bannerList.value = ret?.data?.list || [];
  } catch (error) {
    console.error('获取Banner失败:', error);
  }
};

// 获取站院基本信息
const getCourtyardInfo = async () => {
  try {
    const params = {
      courtyardId: id.value
    };
    const ret = await getCourtyardById(params);
    courtyardInfo.value = ret?.data || {};
  } catch (error) {
    console.error('获取站院信息失败:', error);
  }
};


// 获取专家团队
const getPageProfessorMien = async () => {
  try {
    const params = {
      params: {
        status: true,
        courtyardId: id.value
      },
      page: {
        pageSize: 10,
        pageNum: 1,
      }
    };
    const ret = await pageProfessorMien(params);
    experts.value = ret?.data?.list || [];
  } catch (error) {
    console.error('获取专家团队失败:', error);
  }
};


// 跳转到专家详情
const goToExpertDetail = (professorId) => {
  router.push(`/yardspecialistdetail/${professorId}?yardId=${id.value}`);
};

// 页面加载时获取数据
onMounted(() => {
  if (id.value) {
    getPageBanners();
    getCourtyardInfo();
    getPageProfessorMien();
  }
});
</script>

<style lang="scss" scoped>
.new-yard {
  min-height: 100vh;
  background-color: #f5f5f5;
  background-image: url('../../assets/xiaoyuan/5.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
  line-height: 1.7;
  padding: 20px;
  width: 100vw;
  margin-left: calc(-50vw + 50%);
  margin-right: calc(-50vw + 50%);
}

.banner {
  width: 100%;
  max-width: 70%;
  margin: 0 auto 30px;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.15);

  img {
    width: 100%;
    height: 700px;
    display: block;
    object-fit: cover;
  }
}

.container {
  max-width: 70%;
  margin: 0 auto;
  background-color: #f9f5ee;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.1);
  position: relative;
}

/* 装饰元素 */
.container::before {
  content: "";
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  bottom: 20px;
  border: 1px solid rgba(6, 128, 67, 0.1);
  border-radius: 4px;
  pointer-events: none;
}

.title {
  text-align: center;
  font-size: 32px;
  color: #065c32;
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 2px solid #068043;
  font-weight: normal;
  position: relative;
}

.title::after {
  content: "";
  display: block;
  width: 80px;
  height: 3px;
  background-color: #068043;
  margin: 10px auto 0;
}

.section {
  margin-bottom: 50px;
  padding-bottom: 30px;
  border-bottom: 1px dashed #e0e0e0;
  position: relative;
}

.section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.section-title {
  font-size: 38px;
  color: #065c32;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  font-weight: normal;
  padding-left: 10px;
}

.section-title::before {
  content: "";
  width: 8px;
  height: 24px;
  background-color: #068043;
  margin-right: 12px;
  border-radius: 4px;
}

.section-content {
  font-size: 24px;
  color: #333;
  line-height: 1.8;
  margin-bottom: 25px;
  text-align: center; /* 让内容居中 */

  :deep(p) {
    margin-bottom: 15px;
    text-align: center; /* 段落居中 */
  }

  :deep(img) {
    max-width: 100%;
    height: auto;
    margin: 15px auto; /* 图片居中 */
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: block;
  }

  :deep(strong) {
    color: #068043;
    font-weight: 600;
  }
}


/* 专家列表样式 */
.experts-section {
  margin-top: 70px;
  padding-top: 30px;
  border-top: 1px dashed #e0e0e0;
}

.experts-container {
  display: flex;
  flex-wrap: wrap;
  gap: 50px;
  padding: 20px 0 30px;
  justify-content: flex-start;
  align-items: flex-start;
}

.expert-card {
  min-width: 210px;
  max-width: 250px;
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(0,0,0,0.08);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  border: 1px solid #cad8c5;
  cursor: pointer;

  &:hover {
    transform: translateY(-8px);
  }
}

.expert-photo {
  width: 100%;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f2f7ef;
  padding: 15px;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
  }
}

.expert-info {
  padding: 15px;
  text-align: center;
  background-color: #f9fcf9;
  border-top: 1px solid #e8f4ea;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.expert-name {
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
  font-size: 20px;
  color: #065c32;
}

.expert-title {
  font-size: 18px;
  color: #068043;
  margin-bottom: 8px;
  font-style: normal;
}

.expert-major, .expert-contact {
  font-size: 14px;
  color: #555;
  line-height: 1.6;
  margin-bottom: 4px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .banner {
    max-width: 95%;
  }
  
  .container {
    max-width: 95%;
    padding: 25px 15px;
  }
  
  .title {
    font-size: 26px;
    margin-bottom: 30px;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  .experts-container {
    gap: 20px;
    flex-wrap: wrap;
  }
  
  .expert-card {
    min-width: 160px;
  }
  
  .section-content {
    text-align: center;
  }
}

@media (max-width: 480px) {
  .new-yard {
    padding: 10px;
  }

  .banner {
    max-width: 98%;
    margin-bottom: 20px;
  }

  .container {
    max-width: 98%;
    padding: 20px 10px;
  }

  .experts-container {
    flex-direction: column;
    align-items: center;
    flex-wrap: wrap;
  }

  .expert-card {
    width: 100%;
    max-width: 280px;
  }
}
</style>
